/******************************************************************************
 * Copyright (C) 2011 ShenZhen ComTop Information Technology Co.,Ltd
 * All Rights Reserved.
 * 本软件为深圳康拓普开发研制。未经本公司正式书面同意，其他任何个人、团体不得使用、
 * 复制、修改或发布本软件.
 *****************************************************************************/

package com.code.common.sessioncache.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Request包装类
 * 
 * @author 郑重
 * @since 1.0
 * @version 2010-8-25 郑重
 */
public class HttpServletRequestWrapper extends javax.servlet.http.HttpServletRequestWrapper {
    
    /**
     * 新会话ID
     */
    private final String newSessionId;
    
    /**
     * 旧会话ID
     */
    private final String oldSessionId;
    
    /**
     * @param newSessionId 新的session编号
     * @param oldSessionId 旧的session编号
     * @param request HttpServletRequest
     */
    public HttpServletRequestWrapper(String newSessionId, String oldSessionId, HttpServletRequest request) {
        super(request);
        this.newSessionId = newSessionId;
        this.oldSessionId = oldSessionId;
    }
    
    /**
     * 返回session
     * 
     * @param create 是否创建新会话
     * @return session对象
     */
    @Override
    public HttpSession getSession(boolean create) {
        HttpSession objSession = super.getSession(create);
        if (objSession != null) {
            objSession = new HttpSessionSidWrapper(newSessionId, oldSessionId, super.getSession(create));
        }
        return objSession;
    }
    
    /**
     * @return 返回session
     */
    @Override
    public HttpSession getSession() {
        return new HttpSessionSidWrapper(newSessionId, oldSessionId, super.getSession());
    }
    
}